package com.demo.resourcecode.c6;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//编写自定义的属性编辑器
public class DatePropertyEditor extends PropertyEditorSupport {

	private String format = "yyyy-MM-dd";

	public DatePropertyEditor() {
		super();
		System.out.println("init DatePropertyEditor");
	}

	public void setFormat(String format){
		System.out.println(format);
		this.format = format;
	}

	@Override
	public void setAsText(String arg0) throws IllegalArgumentException {
		System.out.println("arg0:" + arg0);
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			Date d = sdf.parse(arg0);
			this.setValue(d);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
